and && or ||

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    and && or ||

    "and" is not the same like && , also, "or" is not same like ||

    && is higher priority than "and" , also, || is higher priority than "or".

    For example:
    PHP Code:
    $a && $b || $c
    is not the same like:
    PHP Code:
    $a and $b || $c
    the first thing is:
    (a and b) or c

    the second:
    a and (b or c)

    Because || has got a higher priority than and, but less than && .

    Using always [ && and || ] or [ AND and OR ] would be okay, but than you should at least respect the following:

    PHP Code:
    $a $b && $c;
    $a $b and $c
    the first code will set $a to the result of the comparison $b with $c, both have to be true, while the second code line will set $a like $b and THAN - after that - compare the success of this with the value of $c .
    <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

    #2
    i dnt undastand wth u talkn about. I use and and or, easier to read.

    Comment


      #3
      Originally posted by CreativityKills View Post
      i dnt undastand wth u talkn about. I use and and or, easier to read.
      Its like mats, look it this way

      and is +
      or is -
      && is *
      || is /

      you probably know that is you have an expresion a+b*c=d its the same as a+(b*c)=d not the (a+b)*c=d. the * simply have a priority over + and is checked first. same is with 'and' and '&&'
      PHP Code:
      $("#mfreak").find(".head brain").clone(); 
      Progress:
      Code:
      [|||___________________________] : 5%
      Output:
      Code:
      Memory limit reached, unable to complete operation.
      Support answer:
      Code:
      Try using a super uber strong mega computer to reach at least 10%.

      Comment


        #4
        Originally posted by CreativityKills View Post
        i dnt undastand wth u talkn about. I use and and or, easier to read.
        Look at this example from my site script:

        PHP Code:
        if (!empty($a) and check_it($a) || strlen($a) != 32) { exit(errors()); } 
        if u write it like this:

        PHP Code:
        if (!empty($a) && check_it($a) || strlen($a) != 32) { exit(errors()); } 
        index page will not open, this is gonna end up with exit; always because of priority. Its not the same.
        <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

        Comment


          #5
          Most of my scripts use || and && i never used (AND OR OR)
          Visit: Chat4u.mobi - The New Lay Of being a site of your dreams!
          Visit: WapMasterz Coming Back Soon!
          _______
          SCRIPTS FOR SALE BY SUBZERO
          Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders.
          FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others...
          _______
          Info & Tips
          php.net
          w3schools.com

          Comment


            #6
            Me too until i came across this particular problem, when i researched a bit and used only once "and" in the script insted &&.
            Last edited by arnage; 24.07.11, 14:16.
            <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

            Comment


              #7
              Originally posted by arnage View Post
              Look at this example from my site script:

              PHP Code:
              if (!empty($a) and check_it($a) || strlen($a) != 32) { exit(errors()); } 
              if u write it like this:

              PHP Code:
              if (!empty($a) && check_it($a) || strlen($a) != 32) { exit(errors()); } 
              index page will not open, this is gonna end up with exit; always because of priority. Its not the same.
              i undastand bt really it boils down to coding style. Me i usually take note of that, so i make use of brackets to tell php which i wana run 1st.
              PHP Code:
              // this
              $calc 66 20 8;

              // is not
              $calc 66 + (20 8);

              // ur examply my way
              if ( ( isset($a) AND ! empty($a) AND check_it($a) ) OR strlen($a) !== 32) {
              exit(
              errors());

              Comment


                #8
                Thats a different thing mate, like step further, i just talking about this.

                PHP: Logical Operators - Manual
                <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

                Comment

                Working...
                X